/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * nihongo
 * Copyright (C) Massimiliano Maniscalco 2012 <massi.neptune@yahoo.com>
 * 
nihongo is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * nihongo is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PARSER_XML_H_
#define _PARSER_XML_H_

#include <gtkmm.h>
#include <libxml++/libxml++.h>
#include "parola.h"
#include "kanji.h"
#include "esempio.h"
#include "lezione.h"


using namespace std;

class ParserXML: public xmlpp::SaxParser 
{
	
public:
	inline ParserXML() :
		codice_classe ( 0 ), codice_elemento ( 0 ), indice ( 0 ), vox ( 0 ), verbum ( new Parola() ), signum ( new Kanji() ), exemplum ( new Esempio() ), lectio ( new Lezione() )
	{ }
	virtual inline ~ParserXML();

	typedef sigc::signal<void, Glib::ustring> Signal_attribute_lang;
	inline Signal_attribute_lang signal_attribute_lang ( void ) { return commit_attribute_lang; }
	typedef sigc::signal<void, Parola> Signal_parola_imported;
	inline Signal_parola_imported signal_parola_imported ( void ) { return commit_import_parola; }
	typedef sigc::signal<void, Kanji> Signal_kanji_imported;
	inline Signal_kanji_imported signal_kanji_imported ( void ) { return commit_import_kanji; }
	typedef sigc::signal<void, Esempio> Signal_esempio_imported;
	inline Signal_esempio_imported signal_esempio_imported ( void ) { return commit_import_esempio; }
	typedef sigc::signal<void, Lezione> Signal_lezione_imported;
	inline Signal_lezione_imported signal_lezione_imported ( void ) { return commit_import_lezione; }
	typedef sigc::signal<void> Signal_import_end;
	inline Signal_import_end signal_import_end ( void ) { return commit_import_end; }

protected:
#ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
	virtual void on_start_document();
	virtual void on_end_document();
	virtual void on_start_element(const Glib::ustring& name, const AttributeList& properties);
	virtual void on_end_element(const Glib::ustring& name);
	virtual void on_characters(const Glib::ustring& characters);
	virtual void on_comment(const Glib::ustring& text);
	virtual void on_warning(const Glib::ustring& text);
	virtual void on_error(const Glib::ustring& text);
	virtual void on_fatal_error(const Glib::ustring& text);
#endif

private:
	int codice_elemento;
	char codice_classe;
	unsigned short indice;
	struct tm dataOra;
	Signal_attribute_lang commit_attribute_lang;
	Signal_parola_imported commit_import_parola;
	Signal_kanji_imported commit_import_kanji;
	Signal_esempio_imported commit_import_esempio;
	Signal_lezione_imported commit_import_lezione;
	Signal_import_end commit_import_end;
	Voce *vox;
	Parola *verbum;
	Kanji *signum;
	Esempio *exemplum;
	Lezione *lectio;
	
};

inline ParserXML::
~ParserXML()
{
	if ( verbum )
		delete verbum;
	if ( signum )
		delete signum;
	if ( exemplum )
		delete exemplum;
	if ( lectio )
		delete lectio;
}

#endif // _PARSER_XML_H_
